<template>
  <el-dialog title="采购到货单选择"
             v-if="showFlag"
             :visible.sync="showFlag"
             :modal=false
             width="80%"
             center
  >
    <el-table border v-loading="loading" :data="arrivedList" @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
      <el-table-column width="55" align="center">
        <template v-slot="scope">
          <el-radio v-model="selectedArrivedId" :label="scope.row.id" @change="handleRowChange(scope.row)">{{ "" }}</el-radio>
        </template>
      </el-table-column>
      <el-table-column label="到货单编号" align="center" prop="arrivedCode"/>
      <el-table-column label="到货日期" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="供应商名称" align="createTime" prop="vendorName"/>
      <el-table-column label="联系人" align="center" prop="contact"/>
      <el-table-column label="联系人-电话" align="center" prop="contactTel"/>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="showFlag=false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {getArrivedList} from "@/api/mes/wm/itemrecpt";
export default {
  name: "ArrivedSelect",
  dicts: ['erp_payment_type'],
  props: {
    vendorId:null
  },
  data() {
    return {
      showFlag: false,
      selectedArrivedId: undefined,
      selectedRow: undefined,
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 供应商表格数据
      arrivedList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 30,
        vendorId:this.vendorId
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    /*this.getList();*/
  },
  watch: {
    vendorId(newVal) {
      if (newVal) {
        this.queryParams.vendorId = newVal;
        this.getList();
      }
    }
  },
  methods: {
    /** 查询供应商列表 */
    getList() {
      this.loading = true;
      getArrivedList(this.queryParams).then(response => {
        this.arrivedList = response.data;
        this.loading = false;
      });
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRow = row;
      }
    },
    //行双击选中
    handleRowDbClick(row) {
      if (row) {
        this.selectedRow = row;
        this.$emit('onSelected', this.selectedRow);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRow = row;
      }
    },
    //确定选中
    confirmSelect() {
      if (this.selectedArrivedId == null || this.selectedArrivedId == 0) {
        this.$notify({
          title: '提示',
          type: 'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected', this.selectedRow);
      this.showFlag = false;
    }
  }
};
</script>
